﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IRepository;//引用接口的命名空间
using Repository;//引用实现接的命名空间
using WorkModel;
using Microsoft.AspNetCore.Authorization;

namespace WorkApi.Controllers
{
    [Route("api/[controller]")]
 //  [Authorize]
    [ApiController]
    
    public class JuSeController : ControllerBase
    {
        //依赖注入接口
        private IJueSeintfas ma = null;
        //把接口注入到构造函数里(ctor)
        public JuSeController(IJueSeintfas mb)
        {
            ma = mb;//ma相当于bll
        }
        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cIndex"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        [Route("JueSeShowd")]
        [HttpGet]
        public IActionResult JueSeShowd(string name = "", int cIndex = 1, int pSize = 2)
        {
            name += "";
            int rCount;
            List<Juese> li = ma.JueSeShow(name, cIndex, pSize, out rCount);
            return Ok(new { data = li, code = 0, count = rCount });
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("JuSerDelete")]
        [HttpPost]
        public int JuSerDelete(string id)
        {
            int n = ma.JuSerDelete(id);
            return n;
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>

        [Route("JuSerAdd")]
        [HttpPost]
        public int JuSerAdd([FromForm] Juese m)
        {
            int n = ma.JuSerAdd(m);
            return n;
        }
        /// <summary>
        /// 反填角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("JuSerFan")]
        [HttpGet]
        public IActionResult JuSerFan(int id)
        {
            var n = ma.JuSerFan(id);
            return Ok(new { data = n, code = 0 });
        }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("JuSerUpt")]
        [HttpPost]
        public int JuSerUpt([FromForm] Juese m)
        {
            int n = ma.JuSerUpt(m);
            return n;
        }

        //-----------------系统表----------------------
        [Route("XiTongShowd")]
        [HttpGet]
        public IActionResult XiTongShowd(DateTime Begintime, DateTime Overtime, int cIndex = 1, int pSize = 7)
        {
            int rCount;
            List<Xitong> li = ma.XTShow(Begintime, Overtime, cIndex, pSize, out rCount);
            return Ok(new { data = li, code = 0, count = rCount });
        }
        /// <summary>
        /// 删除系统数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("XTDelete")]
        [HttpPost]
        public int XTDelete(string id)
        {
            int n = ma.XiTongDelete(id);
            return n;
        }
        /// <summary>
        /// 修改状态1
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("XTUptShi1")]
        [HttpPost]
        public int XTUptShi1(string id)
        {
            int n = ma.XiTongShi1(id);
            return n;
        }
        /// <summary>
        /// 修改状态0
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("XTUptShi0")]
        [HttpPost]
        public int XTUptShi0(string id)
        {
            int n = ma.XiTongShi0(id);
            return n;
        }

        /// <summary>
        /// 系统表添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("XTAdd")]
        [HttpPost]
        public int XTAdd([FromForm] Xitong m)
        {
            int n = ma.XiTongAdd(m);
            return n;
        }
        /// <summary>
        /// 系统表反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("XTFan")]
        [HttpGet]
        public IActionResult XTFan(int id)
        {
            var n = ma.XiTongFan(id);
            return Ok(new { data = n, code = 0 });
        }
        /// <summary>
        /// 系统表修改
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("XTUpt")]
        [HttpPost]
        public int XTUpt([FromForm]Xitong m)
        {
            int n = ma.XiTongUpt(m);
            return n;
        }












        //----------------------字典表---------------------------------------
        /// <summary>
        /// 显示+查询+分页
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cIndex"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
         
        [Route("ZDShowd")]
        [HttpGet]
        public IActionResult ZDShowd(string name = "", int cIndex = 1, int pSize = 2)
        {
            name += "";
            int rCount;
            List<ZiDian> li = ma.ZDShow(name, cIndex, pSize, out rCount);
            return Ok(new { data = li, code = 0, count = rCount });
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("ZDAdd")]
        [HttpPost]
        public int ZDAdd([FromForm] ZiDian m)
        {
            int n = ma.ZDAdd(m);
            return n;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("ZDUpt")]
        [HttpPost]
        public int ZDUpt([FromForm] ZiDian m)
        {
            int n = ma.ZDUpt(m);
            return n;
        }
        /// <summary>
        ///反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("ZDFan")]
        [HttpGet]
        public IActionResult ZDFan(int id)
        {
            var n = ma.ZDFan(id);
            return Ok(new { data = n, code = 0 });
        }
        /// <summary>
        /// 删除支持批删
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("ZDDeleteAll")]
        [HttpPost]
        public int ZDDeleteAll(string id)
        {
            int n = ma.ZDDeleteAll(id);
            return n;
        }
        //---------------请假表-------------------------
        /// <summary>
        /// 请假表显示
        /// </summary>
        /// <param name="Lbegintime"></param>
        /// <param name="Lovertime"></param>
        /// <param name="cIndex"></param>
        /// <param name="pSize"></param>
        /// <returns></returns>
        [Route("LeaveShow")]
        [HttpGet]
        public IActionResult LeaveShow( string bh="" ,/*DateTime Lbegintime, DateTime Lovertime,*/ int cIndex=1, int pSize=2)
        {
            int rCount;
            bh += "";
            List<Leave> li = ma.LeaveShow(bh,/*Lbegintime, Lovertime,*/ cIndex, pSize,out rCount);

            return Ok(new { data = li, code = 0, count = rCount });
        }
        /// <summary>
        /// 请假表添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("LeaveAdd")]
        [HttpPost]
        public int LeaveAdd([FromForm] Leave m)
        {
            int n = ma.LeaveAdd(m);
            return n;
        }

        /// <summary>
        /// 请假表添加Vue用
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("LeaveAddVue")]
        [HttpPost]
        public int LeaveAddVue(Leave m)
        {
            int n = ma.LeaveAdd(m);
            return n;
        }
        /// <summary>
        ///请假表修改
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [Route("LeaveUpt")]
        [HttpPost]
        public int LeaveUpt([FromForm] Leave m)
        {
            int n = ma.LeaveUpt(m);
            return n;
        }
        /// <summary>
        /// 请假表删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("LeaveDelete")]
        [HttpPost]
        public int LeaveDelete(string id)
        {
            var n = ma.LeaveDelete(id);
            return n;
        }
        /// <summary>
        ///请假表(反填)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("LeaveFan")]
        [HttpGet]
        public IActionResult LeaveFan(int id)
        {
            var n = ma.LeaveFan(id);
            return Ok(new { data = n, code = 0 });
        }
    }
}
